﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplicationPlatform.Comm
{
    public partial class UCPageSelect : UserControl
    {

        private bool IsLoad = false;

        public UCPageSelect()
        {
            InitializeComponent();
        }

        #region 属性
        private int m_PageCount = 0;

        /// <summary>
        /// 总页数
        /// </summary>
        [Description("总页数")]
        public int PageCount
        {
            get
            {
                return m_PageCount;
            }
            set
            {
                m_PageCount = value;

                if(value != 0){
                    GetComBoxValue();
                    IsLoad = true;
                }
            }
        }

        private int m_RecordCount = 0;

        [Description("总记录数")]
        public int RecordCount
        {
            get
            {
                return m_RecordCount;
            }
            set
            {
                m_RecordCount = value;
            }
        }

        private int m_CurryPage = 0;

        [Description("当前页")]
        public int CurryPage
        {
            get
            {
                return m_CurryPage;
            }
            set
            {
                m_CurryPage = value;
            }
        }

        private int m_PageSize = 0;
        [Description("每页记录数")]
        public int PageSize
        {
            get
            {
                return m_PageSize;
            }
            set
            {
                m_PageSize = value;
            }
        }

        #endregion

        private UCPageInfo m_PageInfo = new UCPageInfo();
        public UCPageInfo PageInfo
        {
            get
            {
                m_PageInfo.CurryPage = CurryPage;
                m_PageInfo.PageCount = PageCount;
                m_PageInfo.PageSize = PageSize;
                m_PageInfo.RecordCount = RecordCount;

                return m_PageInfo;
            }
        }

        public delegate void PageSelectedChanges(int page);
        [Description("翻页事件")]
        public event PageSelectedChanges PageSelectIndexChangeItem;


        private void cmd_CheckPage_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.m_CurryPage = Convert.ToInt32((this.cmd_CheckPage.Text));
            if (PageSelectIndexChangeItem != null)
            {
                PageSelectIndexChangeItem(this.m_CurryPage);
            }
        }
        private void but_prv_Click(object sender, EventArgs e)
        {
            this.m_CurryPage -= 1;
            this.cmd_CheckPage.SelectedIndex = m_CurryPage - 1;
        }

        private void but_Next_Click(object sender, EventArgs e)
        {
            this.m_CurryPage += 1;
            this.cmd_CheckPage.SelectedIndex = m_CurryPage - 1;
        }
        private void but_first_Click(object sender, EventArgs e)
        {
            this.m_CurryPage = 1;
            this.cmd_CheckPage.SelectedIndex = 0;
        }

        private void but_last_Click(object sender, EventArgs e)
        {
            this.m_CurryPage = m_PageCount;
            this.cmd_CheckPage.SelectedIndex = m_PageCount - 1;
        }

        private void GetComBoxValue()
        {
            if (IsLoad)
            {
                cmd_CheckPage.Items.Clear();
            }
            for (int i = 1; i <= m_PageCount; i++)
            {
                this.cmd_CheckPage.Items.Add(i);
            }
            this.cmd_CheckPage.SelectedIndex = 0;
        }

    }
}
